<?php
namespace Home\Controller;
use Think\Controller;
// var_dump($_POST);
class UcenterController extends CommonController {
    public function index(){
    	// $uid = $_SESSION['id'];
    	// $forms = M('mvp_forms');
    	// $forms->create();
    	// $finfos = $forms->where("uid = ".$uid)->select();
    	// var_dump($finfos);die;
    	// $finfos['']
    	// $this->assign('finfos','finfos');
    	
    	// echo $cid;
    	// 创建产品模型
    	$Foods = M('mvp_foods');
        //创建优惠模型
        // $Sell = M('mvp_sell');
        $sellinfo = $Foods->select();
        $finfo = $Foods->where($where)->order('id desc')->select();
        // var_dump($sellinfo);
        
    	//分配
        $this->assign('finfo',$finfo);
        $this->assign('cid',$cid);
    	$this->assign('islogin',$islogin);
    	$this->display();
    }
    public function insert(){
    	$id = $_SESSION['id'];
    	//创建对象
		$user = M('mvp_user');
		if($_FILES['img']['error'] == 0){
			$upload = new \Think\Upload();// 实例化上传类    
			$upload->maxSize   =     3145728 ;// 设置附件上传大小    
			$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型    
			$upload->rootPath = './Public';//手动设置文件上传根目录
			$upload->savePath  =      '/Uploads/Home/'; // 设置附件上传目录    // 上传文件     
			$infos = $upload->upload();
			if(!$infos) {// 上传错误提示错误信息        
				$this->error($upload->getError(),'',10333);    
			}else{// 上传成功        
				$_POST['pic'] = ltrim($upload->rootPath,'.').$infos['img']['savepath'].$infos['img']['savename'];
			}
		}
		//添加主表
		$user->create();
		$numuser = $user->where('id = '.$id)->save();

		//添加附加表
		// 创建对象
		$info = M('mvp_info');
		$_POST['address'] = $_POST['add1'].$_POST['address'];
		$info->create();

		// var_dump($_POST);
		$numinfo=$info->where("uid = ".$id)->save();
		// echo $user->_sql();die;
		// var_dump($numuser);
		// var_dump($numinfo);die;
		//执行判断
		if($numinfo||$numuser){
			$this->success('添加成功',U('Home/index/index'),3);
		}else{
			$this->error('添加失败',U('Home/Ucenter/index'),3);
		}
	}

}

